<?php
require_once 'system/core/Model.php';

class Data_Model extends CI_Model{
	
	function __construct(){
		parent::__construct();
	}
	
	var $_data;
	
	function get_data($ID, $name, $URL, $user, $times, $size, $des, $time){
		return $this->_data = array("ID"=>$ID, "Name"=>$name, "URL"=>$URL, 
				"User"=>$user, "Times"=>$times, "Size"=>$size, "Description"=>$des, "Time"=>$time);
	}
	
	function insert_data($name, $URL, $user, $times, $size, $des, $time){
		$data = $this->get_data(1, $name, $URL, $user, $times, $size, $des, $time);
		unset($data["ID"]);
		$this->db->insert("data", $data);
	}
	
	function delete_data($ID){
		$this->db->where("ID", $ID);
		$this->db->delete("data");
	}
	
	function update_data($ID, $name, $URL, $user, $times, $size, $des, $time){
		$data = $this->get_data($ID, $name, $URL, $user, $times, $size, $des, $time);
		$this->db->where("ID", $ID);
		$this->db->update("data", $data);
	}
	
	function query_data_by_ID($ID){
		$this->db->where("ID", $ID);
		return $this->db->get("data");
	}
	
	function query_data($limit, $offset){
		return $this->db->get("data", $limit, ($offset-1)*$limit);
	}
	
	function getALL(){
		return $this->db->get("data");
	}
	
}
?>